package com.sxg.webSocket;

import com.alibaba.fastjson2.JSON;
import com.sxg.common.core.domain.entity.SysUser;
import com.sxg.system.service.ISysUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.websocket.Session;

@Component
@Slf4j
public class MyRunTask implements Runnable {

    private Session session;

    private Long userId;

    private ISysUserService iSysUserService;

    public MyRunTask() {
    }

    public MyRunTask(Session session, Long userId,ISysUserService redisClient) {
        this.session = session;
        this.userId = userId;
        this.iSysUserService = redisClient;
    }

    @Override
    public void run(){
        boolean open = session.isOpen();
        if (open) {
            SysUser sysUser = iSysUserService.selectUserById(userId);
            session.getAsyncRemote().sendText(JSON.toJSONString(sysUser));
        }
    }
}
